package GUI;

import java.awt.Color;

/**
 * Class for the Setup2 panel in GUI
 */
public class Setup1 extends javax.swing.JPanel {
    tvmGUI master;
    Setup2 Setup2Class;
    
    /**
     * Custom constructor
     * @param tvmGUI Reference to {@link tvmGUI}.
     */
    public Setup1(tvmGUI tvmGUI) {
        master = tvmGUI;
        initComponents();
    }
    
    /**
     * Sets references to other panels
     * @param refSetup2 Reference to Setup2 panel.
     */
    public void setReferences(Setup2 refSetup2) {Setup2Class = refSetup2;}
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        LabSetup1Title = new javax.swing.JLabel();
        LabSetup1HardwareID = new javax.swing.JLabel();
        InSetup1HardwareID = new javax.swing.JTextField();
        LabSetup1StartZone = new javax.swing.JLabel();
        InSetup1StartZone = new javax.swing.JTextField();
        ButSetup1Next = new javax.swing.JButton();
        LabSetup1Error = new javax.swing.JLabel();
        BackgroundPIC = new javax.swing.JLabel();

        setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        LabSetup1Title.setFont(new java.awt.Font("Tahoma", 1, 24)); // NOI18N
        LabSetup1Title.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        LabSetup1Title.setText("Opsæt automat");
        LabSetup1Title.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        add(LabSetup1Title, new org.netbeans.lib.awtextra.AbsoluteConstraints(270, 50, 241, -1));

        LabSetup1HardwareID.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        LabSetup1HardwareID.setText("Indtast maskinens unikke ID kode");
        add(LabSetup1HardwareID, new org.netbeans.lib.awtextra.AbsoluteConstraints(258, 129, 287, -1));
        add(InSetup1HardwareID, new org.netbeans.lib.awtextra.AbsoluteConstraints(307, 149, 180, -1));

        LabSetup1StartZone.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        LabSetup1StartZone.setText("Indtast start zone.");
        add(LabSetup1StartZone, new org.netbeans.lib.awtextra.AbsoluteConstraints(310, 190, 170, -1));
        add(InSetup1StartZone, new org.netbeans.lib.awtextra.AbsoluteConstraints(307, 207, 180, -1));

        ButSetup1Next.setText("Næste");
        ButSetup1Next.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButSetup1NextActionPerformed(evt);
            }
        });
        add(ButSetup1Next, new org.netbeans.lib.awtextra.AbsoluteConstraints(680, 543, 95, 32));

        LabSetup1Error.setFont(new java.awt.Font("Tahoma", 2, 11)); // NOI18N
        LabSetup1Error.setForeground(new java.awt.Color(255, 0, 0));
        LabSetup1Error.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        LabSetup1Error.setText("Fejl - Ugyldig indtastning");
        add(LabSetup1Error, new org.netbeans.lib.awtextra.AbsoluteConstraints(307, 238, 170, -1));

        BackgroundPIC.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Interface/BackgroundGUI.png"))); // NOI18N
        add(BackgroundPIC, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 0, 810, 600));
    }// </editor-fold>//GEN-END:initComponents

    private void ButSetup1NextActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButSetup1NextActionPerformed

        master.hardID = master.isInteger(InSetup1HardwareID.getText());
        master.startZone = master.isInteger(InSetup1StartZone.getText());
        if(master.hardID == -1) {
            LabSetup1Error.setVisible(true);
            LabSetup1HardwareID.setForeground(Color.red);
        } else {
            LabSetup1HardwareID.setForeground(Color.black);
        }
        if(master.startZone == -1) {
            LabSetup1Error.setVisible(true);
            LabSetup1StartZone.setForeground(Color.red);
        } else {
            LabSetup1StartZone.setForeground(Color.black);
        }
        if (master.hardID !=-1 && master.startZone !=-1)
        {
            LabSetup1Error.setVisible(false);
            Setup2Class.LabSetup2Info.setText("Maskin ID: "+master.hardID
                    +"  Zone: "+master.startZone);
            master.ChangePanel(Setup2Class);
        }
    }//GEN-LAST:event_ButSetup1NextActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    public javax.swing.JLabel BackgroundPIC;
    public javax.swing.JButton ButSetup1Next;
    public javax.swing.JTextField InSetup1HardwareID;
    public javax.swing.JTextField InSetup1StartZone;
    public javax.swing.JLabel LabSetup1Error;
    public javax.swing.JLabel LabSetup1HardwareID;
    public javax.swing.JLabel LabSetup1StartZone;
    public javax.swing.JLabel LabSetup1Title;
    // End of variables declaration//GEN-END:variables
}
